In [18]:
import sqlite3
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import plotly.express as px
In [25]:
conn = sqlite3.connect("olist_ecommerce.db")
In [26]:
query = """
SELECT 
  p.product_category_name,
  SUM(oi.price) AS total_sales
FROM order_items oi
JOIN products p ON oi.product_id = p.product_id
GROUP BY p.product_category_name
ORDER BY total_sales DESC
LIMIT 10;
"""
In [27]:
df = pd.read_sql_query(query, conn)
In [34]:
plt.figure(figsize=(10,6))
sns.barplot(
    data=df,
    y="product_category_name",
    x="total_sales",
    palette="crest",
    hue="product_category_name",
    legend=False
)
plt.title("Top 10 Kategori Produk Terlaris di Olist")
plt.xlabel("Total Penjualan (BRL)")
plt.ylabel("Kategori Produk")
plt.tight_layout()
plt.show()
No description has been provided for this image
In [31]:
fig = px.bar(
    df,
    x="total_sales",
    y="product_category_name",
    orientation="h",
    title="Top 10 Kategori Produk Terlaris (Interaktif)",
    color="total_sales",
    color_continuous_scale="Viridis"
)
fig.show()
In [12]:
fig.write_html("top10_produk_.html")
In [ ]: